#include <bits/stdc++.h>
using namespace std;

int a[200005], c[200005], f[200005];

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int n;
    scanf("%d", &n);
    while(n--)
    {
        int ans = 0;
        int k;
        scanf("%d", &k);
        for (int i = 1; i <= k; i++)
            scanf("%d", &a[i]);
        c[1] = 1;
        for (int i = 1; i <= n; i++)
            f[i] = 0;
        for (int i = 2; i <= k; i++)
        {
            if (a[i] == a[i - 1])
            {
                c[i] = c[i - 1];
                f[i] = a[i - 1];
            }
            else
            {
                c[i] = 1 - c[i - 1];
                for (int j = 1; j < i; j++)
                    if (c[i] == c[j])
                        if (a[i] == a[j]) f[i] = a[j];
            }
        }
        for (int i = 1; i <= k; i++)
            ans += f[i];
        printf("%d\n", ans);
    }
    return 0;
}